<template>
  <div class="business_edit">
    <titleDiv
      :title="title"
      :isShow="true"
      text1="创建人："
      text2="创建时间："
      :value1="edit.founder"
      :value2="edit.creatTime"
    ></titleDiv>
    <div class="main">
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="网点管理员：">
          <el-input v-model="form.name" placeholder="如：丁某某"></el-input>
        </el-form-item>
        <el-form-item label="管理员账号：">
          <el-input v-model="form.user" placeholder="如：15713840042"></el-input>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input
            maxlength="500"
            v-model="form.remarks"
            class="textArea"
            type="textarea"
            placeholder
          ></el-input>
        </el-form-item>
        <el-button class="btn" type="primary" @click="sub">提交</el-button>
      </el-form>
    </div>
  </div>
</template>
<script>
import titleDiv from "./view/titleDiv.vue";
import { orgManagerDetail, orgManagerEdit } from "../api/getData.js";
export default {
  name: "business_edit",
  data: function() {
    return {
      title: "编辑人员管理",
      businessId: "",
      edit: {},
      form: {
        name: "",
        describe: ""
      }
    };
  },
  components: {
    titleDiv
  },
  created() {
    this.getParams();
    this.getDetail();
  }, // 创建时
  beforeMount: function() {}, // 挂载之前
  mounted: function() {}, // 挂载之后
  beforeUpdate: function() {}, // 数据更新时调用,在渲染之前
  updated: function() {}, // 数据更新后,渲染后调用(禁止)
  beforeDestroy: function() {}, // 实例销毁前调用,解绑中间层的数据传输
  destroyed: function() {}, // 实例销毁后调用

  methods: {
    getParams() {
      console.log(this.$route.query.id, "传来的参数");
      this.businessId = this.$route.query.id;
    },
    getDetail() {
      orgManagerDetail({
        personid: this.businessId
      })
        .then(res => {
          console.log(res.data);
          if (res.data.code === 0) {
            this.edit = res.data.data;
            this.form.user = res.data.data.user;
            this.form.name = res.data.data.name;
            this.form.remarks = res.data.data.remarks;
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    sub() {
       let str = this.form.user;
      function isPoneAvailable(str) {
        var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
        if (!myreg.test(str)) {
          return false;
        } else {
          return true;
        }
      }
      if (isPoneAvailable(str)) {
        orgManagerEdit({
          personName: this.form.name,
          Logincode: this.form.user,
          remarks: this.form.remarks,
          personid: this.businessId
        })
          .then(res => {
            console.log(res.data);
            if (res.data.code === 0) {
              this.$message({
                message: res.data.msg,
                type: "success"
              });
              var _this = this;
              setTimeout(function() {
                _this.$router.push("/orgPeople/orgPeopleIndex");
              }, 1000);
            } else {
              this.$message.error(res.data.msg);
            }
          })
          .catch(error => {
            console.log(error);
          });
      } else {
        this.$message.error("检查手机号是否输入有误");
      }
    }
  } // 函数
};
</script>
<style lang='scss'>
.business_edit {
  box-sizing: border-box;
  .main {
    background: #fff;
    width: 100%;
    margin-top: 3%;
    padding: 5% 20%;
    .textArea {
      textarea {
        min-height: 240px !important;
      }
    }
    .el-form-item__label {
      font-weight: bold;
    }
    .btn {
      width: 120px;
      height: 32px;
      line-height: 1px;
      margin-left: 80px;
    }
  }
}
</style>

